package jmine.tec.utils.reflection.fast.reflection;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;

import jmine.tec.utils.reflection.fast.AbstractFastClass;
import jmine.tec.utils.reflection.fast.FastClass;
import jmine.tec.utils.reflection.fast.FastConstructor;
import jmine.tec.utils.reflection.fast.FastConstructorImpl;
import jmine.tec.utils.reflection.fast.FastMethod;

/**
 * @author takeshi
 */
public class FastClassImpl extends AbstractFastClass implements FastClass {

    private final Class<?> type;

    private final Collection<FastMethod> methods;

    private final Collection<FastConstructor> constructors;

    /**
     * @param type {@link Class}
     */
    public FastClassImpl(Class<?> type) {
        super();
        this.type = type;
        final Method[] ms = type.getMethods();
        this.methods = new ArrayList<FastMethod>(ms.length);
        for (Method method : ms) {
            this.methods.add(new FastMethodImpl(method));
        }
        this.constructors = new ArrayList<FastConstructor>(type.getConstructors().length);
        for (Constructor<?> ctor : type.getConstructors()) {
            this.constructors.add(new FastConstructorImpl(ctor));
        }
    }

    /**
     * {@inheritDoc}
     */
    public Collection<? extends FastMethod> getMethods() {
        return new ArrayList<FastMethod>(this.methods);
    }

    /**
     * {@inheritDoc}
     */
    public Class<?> getType() {
        return this.type;
    }

    /**
     * {@inheritDoc}
     */
    public Collection<? extends FastConstructor> getConstructors() {
        return new ArrayList<FastConstructor>(this.constructors);
    }

}
